//
//  PhotoCell.m
//  横向滚动照片预览
//
//  Created by 抬头看见柠檬树 on 2017/2/22.
//  Copyright © 2017年 csip. All rights reserved.
//

#import "PhotoCell.h"

@interface PhotoCell ()

@property (nonatomic,strong) UILabel *titleLabel;
@property (nonatomic,strong) UIView *bottomView;
@property (nonatomic,strong) UIImageView *iconImageView;

@end

@implementation PhotoCell
//
//- (void)awakeFromNib {
//    [super awakeFromNib];
//    // Initialization code
//}
//
//- (instancetype)initWithFrame:(CGRect)frame{
//    self = [super initWithFrame:frame];
//
//    if(self){
//        [self.contentView addSubview:self.bottomView];
//        //        [self.bottomView addSubview:self.titleLabel];
//        [self.bottomView addSubview:self.iconImageView];
//
//
//    }
//
//}
//
//- (void)setImageName:(NSString *)imageName
//{
//    //_imageName = imageName;
//
//    self.imageView.image = [UIImage imageNamed:imageName];
//}
//
- (void)setModel:(PhotoCellModel *)model{
    
    _model = model;
    self.iconImageView.contentMode = UIViewContentModeScaleAspectFit;
    
    [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:model.url]];
    
    self.titleLabel.text = model.title;
    
    if(model.isSelect){
       
        self.iconImageView.layer.cornerRadius  = 6.f;
        self.iconImageView.layer.borderWidth = 1.0f;
        self.iconImageView.layer.borderColor = UIColor.blueColor.CGColor;
    }
    else{
        
        self.iconImageView.layer.cornerRadius  = 6.f;
        self.iconImageView.layer.borderWidth = 1.0f;
        self.iconImageView.layer.borderColor = UIColor.clearColor.CGColor;
    }
    self.iconImageView.layer.masksToBounds = YES;
}


- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    
    if(self){
        [self.contentView addSubview:self.bottomView];
        [self.bottomView addSubview:self.titleLabel];
        [self.bottomView addSubview:self.iconImageView];
        
        [self.bottomView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.equalTo(self);
        }];
        
        
        [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.bottomView.mas_left).offset(5.0);
            make.right.equalTo(self.bottomView.mas_right).offset(-5.0);
            make.top.equalTo(self.bottomView.mas_top);
            make.height.mas_equalTo(40);
        }];
        
        [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.titleLabel.mas_bottom);
            make.left.bottom.right.equalTo(self.bottomView);
        }];
       
    }
    return self;
}

//- (void)setModel:(xsAuthorityCollectionViewCellModel *)model
//{
//    _model = model;
//
//    //self.titleLabel.text = model.iconUrlString;
//    if(!kStringIsEmpty(model.title)){
//        self.titleLabel.text = model.title;
//    }
//    else{
//        self.titleLabel.text = @"";
//    }
//
//    XSWeakSelf;
////
//    NSData *urlImageData =  [[SDImageCache sharedImageCache]diskImageDataForKey:model.url];
//    if(urlImageData){
//        weakSelf.iconImageView.image = [UIImage imageWithData:urlImageData];
//    }
//    else{
//        [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:[NSURL URLWithString:model.url] options:SDWebImageDownloaderLowPriority progress:^(NSInteger receivedSize, NSInteger expectedSize, NSURL * _Nullable targetURL) {
//
//        } completed:^(UIImage * _Nullable image, NSData * _Nullable data, NSError * _Nullable error, BOOL finished) {
//                if (image) {
//                    [[SDImageCache sharedImageCache] storeImageDataToDisk:data forKey:model.url];
//
//                    // 图片下载成功，将其设置到UIImageView中
//                    dispatch_async(dispatch_get_main_queue(), ^{
//                        weakSelf.iconImageView.image = image;
//                    });
//                } else {
//                    // 处理错误
//                    NSLog(@"Error downloading image: %@", error);
//                }
//        }];
//    }
//}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (UIView *)bottomView {
    if (!_bottomView) {
        _bottomView = [[UIView alloc] init];
        _bottomView.backgroundColor = UIColor.clearColor;//COLOR_VCViewBgcolor;
    }
    return _bottomView;
}
- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.backgroundColor = UIColor.clearColor;
//        _titleLabel.font = FontSemibold(17);
        _titleLabel.textColor = UIColor.whiteColor;//COLOR_TextGray9B;
        _titleLabel.numberOfLines = 1;
        _titleLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _titleLabel;
}



- (UIImageView *)iconImageView{
    if (!_iconImageView) {
        _iconImageView = [[UIImageView alloc] init];
        ////        _imageView.layer.masksToBounds = YES;
        ////        _imageView.layer.cornerRadius  = 2.f;
        ////        _imageView.layer.borderWidth = 1.0f;
        ////        _imageView.layer.borderColor = [HexRGB(0x444444, 1.0f) CGColor];
        ////        [_imageView setTitleColor:HexRGB(0x444444, 1.0f) forState:UIControlStateNormal];
        ////        [_imageView.titleLabel setFont:FontMedium(14.f)];
        ////        [_imageView addTarget:self action:@selector(otherAction) forControlEvents:UIControlEventTouchUpInside];
        //        [_imageView setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
        //        [_imageView setImage:[UIImage imageNamed:@"editorFontSizeSelect"] forState:UIControlStateSelected];
        //        _iconimageView.image = [UIImage imageNamed:@"BottomSelectCellViewSelectImage"];
        _iconImageView.backgroundColor = UIColor.clearColor;
        //        _iconimageView.hidden = NO;
        _iconImageView.contentMode = UIViewContentModeScaleAspectFill;
    }
    return _iconImageView;
}


@end
